count = 0  # 定义全局变量用于记录查找次数
def BiSearchRe(arr, low, high, key):
    global count
    if low > high:
        return -1
    mid = (low + high) // 2
    count += 1  # 每次递归调用时查找次数加1
    if arr[mid] == key:
        print(f"查找次数为: {count}")
        return mid
    elif arr[mid] < key:
        return BiSearchRe(arr, mid + 1, high, key)
    else:
        return BiSearchRe(arr, low, mid - 1, key)

# 获取用户输入的数组元素，以空格分隔
input_str = input("请输入有序数组元素，以空格分隔: ")
arr = [int(x) for x in input_str.split()]

# 获取用户输入的目标值
key = int(input("请输入待查找元素: "))

result = BiSearchRe(arr, 0, len(arr) - 1, key)
if result != -1:
    print(f"所需要查找值位置: {result}")
else:
    print("无查找值!")